﻿using Nemerle;
using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;

using System;
using System.Collections.Generic;
using System.Linq;

namespace Nemerle2.Compiler
{
  /// <summary>
  /// Description of PNamespace.
  /// </summary>
  [Record]
  public variant PNamespace : PAst
  {
    | Content
      {
        Name        : LocatedList[PId];
        Usings      : LocatedList[PUsing];
        Env         : GlobalEnv;
        Namespaces  : LocatedList[PNamespace];
        Members     : LocatedList[PTypeDeclaration];
      }

    | Error { Msg : Msg; }

    public FullName : string
    {
      [Memoize]
      get
      {
        match(this)
        {
          | Content(Name = name, Env = GlobalEnv where (CurrentNamespace = "")) =>
            $<#..$(name; ".")#>

          | Content(Name = name, Env = GlobalEnv where (CurrentNamespace = ns)) =>
            $<#$ns...$(name; ".")#>

          | Error => ""
        }
      }
    }

    public override ToString() : string
    {
      match (this)
      {
        | Content(Members=mems) => $<#namespace $FullName { ..$(mems; ";"; mem => mem.Name.ToString()) }#>
        | Error(msg)        => msg.ToString()
      }
    }
  }
}
